
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

/**
 * @author yitta
 * @date 2021/11/14 22:38
 */
public class Wordcount {

 //main 函数

        public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException{


            Configuration configuration = new Configuration();
            Job job = Job.getInstance(configuration);

            job.setJarByClass( Wordcount.class);
            // 3、设置 map 和 reduce 类
            job.setMapperClass(WordcountMapper.class);
            job.setReducerClass(WordcountReduce.class);

            // 4、设置 map 输出
            job.setMapOutputKeyClass(Text.class);
            job.setMapOutputValueClass(IntWritable.class);
            // 5、设置最终输出 kv 类型
            job.setOutputKeyClass(Text.class);
            job.setOutputKeyClass(IntWritable.class);

            // 6、设置输入和输出路径
            FileInputFormat.setInputPaths(job, new Path(args[0]));
            FileOutputFormat.setOutputPath(job, new Path(args[1]));

            // 7、提交
            boolean result = job.waitForCompletion(true);
            System.exit(result ? 0 : 1);

        }

    }

